import Ember from 'ember';

export default Ember.Route.extend({
  queryParams: {
    loginType: {
      refreshModel: true
    }
  },
  setupController: function(controller,model){
    var _self = this;
    controller.set('deterDisabled',false);
    controller.set('responseInfo','');
    controller.set('deterSDisabled',false);
    new Ember.RSVP.Promise(function (resolve, reject) {
      //登录入口,先从本地取得当前用户，如果没有则登录
      _self.get("store").query("localstorage/user",{filter:{"current":1}}).then(function (users) {
        console.log("users get.len:" + users.get("length"));
        if(users.get("length")!=0){
          var userEnt = users.get("firstObject");
          console.log("userData get", userEnt);
          if(userEnt.get('current')===1){
            console.log("v");
            _self.get("global_curStatus").setUser(userEnt);
          }
          console.log("get user role",_self.get("global_curStatus").getUser().get('role').get('id'));
          console.log("get loginType",controller.get('loginType'));
          if(_self.get("global_curStatus").getUser().get('role').get('id') == controller.get('loginType')) {
            _self.get("global_curStatus").login().then(function (userRtn) {
              _self.get("global_curStatus").goHome(_self.controllerFor("user-login"));
              console.log("userrtn in rol",userRtn);
              resolve(userRtn);
            });
          }
        }
      });
    });
    this._super(controller, model);

    console.log("controller in",controller);
  },
});
